package com.supermap.dataservice.cloud.productC;

import com.alibaba.dubbo.config.annotation.Service;
import com.supermap.dataservice.mysql.config.DynamicDataSourceContextHolder;
import com.supermap.dataservice.util.JSONUtils;
import com.supermap.dubbo.api.product.GridProductFromChnService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @Author:zhoujian
 * @Desciption:格点产品服务
 * @date:2019-04-18 10:45
 * @version:v1.0.0
 */
@Service
public class GridProductFromChnServiceImpl implements GridProductFromChnService {

    @Autowired
    private GridProductFromChnMapper gridProductFromChnMapper;

    @Override
    public JSONUtils firstCatalog(String type , String areaCode) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        List<Map<String,Object>> list = gridProductFromChnMapper.firstCatalog(type , areaCode);
//        if (systemName != null)
//        {
//            list = gridProductFromChnMapper.firstCatalog(systemName , areaCode);
//        }else {
//          list  = gridProductFromChnMapper.firstCatalog();
//        }
        return new JSONUtils().setData(list).setCountSum(list!= null ? list.size():0);
    }

    @Override
    public JSONUtils selectElementByDataContent(String dataContent ,String areaCode) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        if (areaCode == null || "".equals(areaCode))
            areaCode = "50";
        List<Map<String,Object>> list = gridProductFromChnMapper.selectElementByDataContent(dataContent , areaCode);
        return new JSONUtils().setData(list).setCountSum(list!=null?list.size():0);
    }

    @Override
    public JSONUtils selectProductByContentElementArea(String dataContent, String elementCode, String areaCode) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        List<Map<String,Object>> list = gridProductFromChnMapper.selectProductByContentElementArea(dataContent, elementCode, areaCode);
        return new JSONUtils().setData(list).setCountSum(list != null?list.size(): 0);
    }


}